package com.gxa.controller;


import com.gxa.common.base.LayuiResultJson;
import com.gxa.common.base.Result;
import com.gxa.domain.entity.Coach;
import com.gxa.service.CoachService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/coach")
public class CoachController {

    @Autowired
    private CoachService coachService;

    @RequestMapping(value = "/getAllCoachsById", method = RequestMethod.GET)
    @ResponseBody
    public Result getAllCoachsById(@RequestParam("id") Integer id) {
        Result r = coachService.selectAllUsersById(id);
        return r;
    }


    @RequestMapping(value = "/updateCoach", method = RequestMethod.POST)
    @ResponseBody
    public Result updateCoach(Integer id, Coach coach) {
        coach.setId(id);
        return coachService.updateCoach(coach);
    }

    @RequestMapping(value = "/deleteCoachById", method = RequestMethod.POST)
    @ResponseBody
    public Result deleteCoachById(Integer id) {

        return coachService.deleteCoachById(id);
    }

    @RequestMapping(value = "/insertCoach", method = RequestMethod.POST)
    @ResponseBody
    public Result insertCoach(@RequestBody Coach coach) {
        System.out.println("进入教练增加功能");
        return coachService.insertCoach(coach);
    }


    @RequestMapping(value = "/getCoachList", method = RequestMethod.GET)
    @ResponseBody
    public List<Coach> getCoachList() {

        return coachService.getCoachList();
    }

    @RequestMapping(value = "/getCoachListByPage", method = RequestMethod.GET)
    @ResponseBody
    public List<Coach> getCoachListByPage(@RequestParam("pageNum") int pageNum, @RequestParam("pageSize") int pageSize) {
        return coachService.getoachListByPage(pageNum, pageSize);
    }

    @RequestMapping(value = "/countCoachs", method = RequestMethod.GET)
    @ResponseBody
    public int countCoachs() {
        return coachService.countCoachs();
    }

    @RequestMapping(value = "/findCoachByName", method = RequestMethod.GET)
    @ResponseBody
    public LayuiResultJson findCoachByName(String title, int page, int limit) {

        System.out.println(title + page + limit);

        return coachService.findCoachByName(title, page, limit);
    }

    @RequestMapping(value = "/findCoachAll", method = RequestMethod.GET)
    @ResponseBody
    public LayuiResultJson findUserAll(@RequestParam("page") int page,
                                       @RequestParam("limit") int limit) {

        String title = "";
        System.out.println(title + page + limit);

        return coachService.findCoachByName(title, page, limit);
    }

    @RequestMapping(value = "/update", method = RequestMethod.POST)
    @ResponseBody
    public Result update( Coach coach) {
        return coachService.update(coach);
    }
}